﻿using SqlSugar;
using SqlsugarBlog.IRepository;
using SqlsugarBlog.IService;
using System.Linq.Expressions;

namespace SqlsugarBlog.Service
{
    public class BaseService<T> : IBaseService<T> where T : class, new()
    {
        protected IBaseRepository<T> _IRepository;
        public async Task<bool> AddAsync(T entity)
        {
            return await _IRepository.AddAsync(entity);
        }

        public async Task<bool> DeleteAsync(int id)
        {
            return await _IRepository.DeleteAsync(id);
        }

        public async Task<bool> ModifyAsync(T entity)
        {
            return await _IRepository.ModifyAsync(entity);
        }

        public async Task<List<T>> QueryAsync()
        {
            return await _IRepository.QueryAsync();
        }

        public async Task<List<T>> QueryAsync(Expression<Func<T, bool>> expression)
        {
            return await _IRepository.QueryAsync(expression);
        }

        public async Task<List<T>> QueryAsync(int page, int size, RefAsync<int> total)
        {
            return await _IRepository.QueryAsync(page,size ,total);
        }

        public async Task<List<T>> QueryAsync(Expression<Func<T, bool>> expression, int page, int size, RefAsync<int> total)
        {
            return await _IRepository.QueryAsync(expression, page, size, total);
        }

        public async Task<T> QueryByIdAsync(int id)
        {
            return await _IRepository.QueryByIdAsync(id);
        }
    }
}